<?php
	check_login();
	$a = getAction();

	switch($a) {
		case 'index':
			$title=trim($_GET['title']);
			$sql="select *  from " . table('weixin') . " where 1=1";
			$url="admin.php?m=weixinapi";
			
			if(!empty($title))
			{
				$sql .=" and title like '%".$title."%' ";
				$url.="&title={$title}";
			}
			
			$sql .=	" order by id desc ";	

			$rscount=$db->getOne("select count(1) from ($sql) temp");
			$pagesize=20;
			$page=max(1,intval($_GET['page']));
			$start=($page-1)*$pagesize;
			$sql.=" limit $start,$pagesize";

			$smarty->assign("pagelist",multipage($rscount,$pagesize,$page,$url));
			$smarty->assign("list", $db->getAll($sql));

			$smarty->display("weixinapi.html");
	
			break;	
	
		case 'add':
			if($_POST) {
				$id=intval($_POST['id']);
				$formData = $_POST["formData"];
				ckempty($formData["title"],'');
				
				if($id)
				{
					$formData["update_time"] = getNowTime();
					$db->update("weixin", $formData, " and id = $id");
				}else
				{
					$formData["insert_time"] = getNowTime();
					$formData["update_time"] = getNowTime();
					$db->insert("weixin", $formData);
				}
				 
				errback("文字关键字保存成功", "admin.php?m=weixinapi");
				exit();
			} else {
				$id=intval($_GET['id']);
				if($id)
				{
					$sql="select *  from " . table('weixin')." where id = $id ";
					$formData = $db->getRow($sql);
					$smarty->assign("formData", $formData);
				}
				$smarty->display("weixinapi_add.html");
			}
				
			break;
	
		case 'del':
			$id=intval($_GET['id']);
			$db->query("delete from " . table('weixin') . " where id='$id' ");
			gourl();
			break;
	}
	?>